package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PubBlogTag;
import com.ruoyi.system.service.IPubBlogTagService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博客标签Controller
 * 
 * @author ruoyi
 * @date 2024-02-25
 */
@RestController
@RequestMapping("/system/tag")
public class PubBlogTagController extends BaseController
{
    @Autowired
    private IPubBlogTagService pubBlogTagService;

    /**
     * 查询博客标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:tag:list')")
    @GetMapping("/list")
    public TableDataInfo list(PubBlogTag pubBlogTag)
    {
        startPage();
        List<PubBlogTag> list = pubBlogTagService.selectPubBlogTagList(pubBlogTag);
        return getDataTable(list);
    }

    /**
     * 导出博客标签列表
     */
    @PreAuthorize("@ss.hasPermi('system:tag:export')")
    @Log(title = "博客标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PubBlogTag pubBlogTag)
    {
        List<PubBlogTag> list = pubBlogTagService.selectPubBlogTagList(pubBlogTag);
        ExcelUtil<PubBlogTag> util = new ExcelUtil<PubBlogTag>(PubBlogTag.class);
        util.exportExcel(response, list, "博客标签数据");
    }

    /**
     * 获取博客标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:tag:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pubBlogTagService.selectPubBlogTagById(id));
    }

    /**
     * 新增博客标签
     */
    @PreAuthorize("@ss.hasPermi('system:tag:add')")
    @Log(title = "博客标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PubBlogTag pubBlogTag)
    {
        return toAjax(pubBlogTagService.insertPubBlogTag(pubBlogTag));
    }

    /**
     * 修改博客标签
     */
    @PreAuthorize("@ss.hasPermi('system:tag:edit')")
    @Log(title = "博客标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PubBlogTag pubBlogTag)
    {
        return toAjax(pubBlogTagService.updatePubBlogTag(pubBlogTag));
    }

    /**
     * 删除博客标签
     */
    @PreAuthorize("@ss.hasPermi('system:tag:remove')")
    @Log(title = "博客标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pubBlogTagService.deletePubBlogTagByIds(ids));
    }
}
